﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;

using SharedGenomics.TextMining;

namespace SharedGenomics.Workbench.Tests.TextMining
{
    [TestClass]
    public class ScoredTermTests
    {
        [TestMethod]
        public void ConstructorTest()
        {
            ScoredTerm st = new ScoredTerm("term", 2.1);
            Assert.AreEqual("term", st.Term);
            Assert.AreEqual(2.1, st.CValue);
        }

        [TestMethod]
        public void CompareToTestGreater()
        {
            ScoredTerm st = new ScoredTerm("term1", 2.0);
            int result = st.CompareTo(new ScoredTerm("term2", 1.0));

            Assert.AreEqual(1, result);
        }

        [TestMethod]
        public void CompareToTestEqual()
        {
            ScoredTerm st = new ScoredTerm("term1", 2.0);
            int result = st.CompareTo(new ScoredTerm("term2", 2.0));

            Assert.AreEqual(0, result);
        }

        [TestMethod]
        public void CompareToTestLess()
        {
            ScoredTerm st = new ScoredTerm("term1", 2.0);
            int result = st.CompareTo(new ScoredTerm("term2", 3.0));

            Assert.AreEqual(-1, result);
        }

        [TestMethod]
        public void EqualsTestSame()
        {
            ScoredTerm st1 = new ScoredTerm("term", 0.1);
            ScoredTerm st2 = new ScoredTerm("term", 0.1);

            Assert.AreEqual(st1, st2);
        }

        [TestMethod]
        public void EqualsTestNameDifferent()
        {
            ScoredTerm st1 = new ScoredTerm("term", 0.1);
            ScoredTerm st2 = new ScoredTerm("abc", 0.1);

            Assert.IsFalse(st1.Equals(st2));
        }

        [TestMethod]
        public void EqualsTestScoreDifferent()
        {
            ScoredTerm st1 = new ScoredTerm("term", 0.1);
            ScoredTerm st2 = new ScoredTerm("term", 0.2);

            Assert.IsFalse(st1.Equals(st2));
        }

        [TestMethod]
        public void EqualsTestNull()
        {
            ScoredTerm st1 = new ScoredTerm("term", 0.1);

            Assert.IsFalse(st1.Equals(null));
        }

        [TestMethod]
        public void EqualsTestInvalidType()
        {
            ScoredTerm st1 = new ScoredTerm("term", 0.1);

            Assert.IsFalse(st1.Equals("abc"));
        }

        [TestMethod]
        public void GetHashCodeTestEqual()
        {
            //equal objects should have the same hash code
            ScoredTerm st1 = new ScoredTerm("term", 0.1);
            ScoredTerm st2 = new ScoredTerm("term", 0.1);

            Assert.AreEqual(st1.GetHashCode(), st2.GetHashCode());
        }

        [TestMethod]
        public void WordsTestSingle()
        {
            ScoredTerm t = new ScoredTerm("term", 0.1);
            Assert.AreEqual(1, t.Words.Count);
        }

        [TestMethod]
        public void WordsTestMultipleSpaceSeparator()
        {
            ScoredTerm t = new ScoredTerm("word1     word2 word3", 0.1);
            Assert.AreEqual(3, t.Words.Count);
        }

        [TestMethod]
        public void WordsTestMultiple()
        {
            ScoredTerm t = new ScoredTerm("word1 word2 word3", 0.1);
            Assert.AreEqual(3, t.Words.Count);
        }

        [TestMethod]
        public void WordsTestNull()
        {
            ScoredTerm t = new ScoredTerm(null, 0.1);
            Assert.AreEqual(0, t.Words.Count);
        }
    }
}
